﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace A6
{
    public partial class Form1: Form
    {
        private OrderService orderService;
        
        public Form1(OrderService _orderService)
        {
            InitializeComponent();
            orderService = _orderService;
        }
        public void UpdateResultsInRichTextBox(List<Order> orders)
        {
            // 清空现有内容
            richTextBox1.Clear();

            // 设置标题样式
            richTextBox1.SelectionFont = new Font("微软雅黑", 10, FontStyle.Bold);
            richTextBox1.AppendText(" 订单查询结果 \n\n");

            // 设置正文样式
            richTextBox1.SelectionFont = new Font("微软雅黑", 10);
            if(orders.Count == 0)
            richTextBox1.AppendText("查询结果为空！");
            foreach (var order in orders)
            {
                // 添加订单信息
                richTextBox1.AppendText(order.ToString());
            }

            // 滚动到顶部
            richTextBox1.ScrollToCaret();
        }
        private void button5_Click(object sender, EventArgs e)
        {
            var Query = new query(orderService);
            Query.OnSearchCompleted = UpdateResultsInRichTextBox;
            Query.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var next = new Form2(orderService);
            next.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            var change = new Form3(orderService);
            change.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var del = new delete(orderService);
            del.Show();
        }
    }
}
